home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_056 / mcad / tdp / t2fsource / t2f.c < prev   
C/C++ Source or Header  |  1992-05-06  |  1KB  |  51 lines

  1. /* t2f.c - program to convert text file to binary file for tdp */
  2.  
  3. #include <stdio.h>
  4. #include "ffp.h"
  5. #define MAXLINE 80
  6.  
  7. main(argc,argv)
  8. char *argv[];
  9. int argc;
  10. {
  11.    int i, nx, ny, debug;
  12.    char line[80];
  13.    FFP zd;
  14.    FILE *f_in, *f_out, *fopen();
  15.  
  16.    if (argc<4) {
  17.       printf("usage: t2f nx ny file");
  18.       printf("   where nx(ny) is the number of columns(rows) in the data");
  19.       printf(" array to be written.  'file' is the name of a text file");
  20.       printf(" containing nx*ny lines.  The lines must start with a");
  21.       printf(" number (which is the data to be written in binary)\n");
  22.       exit(1);
  23.    }
  24.    debug = argc>4;
  25.    nx = atoi(argv[1]); ny = atoi(argv[2]);
  26.  
  27.    f_in= fopen(argv[3],"r");
  28.    if (!f_in)
  29.       {printf("can't open input file\n"); exit(1);}
  30.  
  31.    f_out = fopen("t2f.out","w");
  32.    if (!f_out)
  33.       {printf("can't open output file\n"); exit(1);}
  34.  
  35.    (void)fwrite((char *)&nx,4,1,f_out);
  36.    (void)fwrite((char *)&ny,4,1,f_out);
  37.    if (debug) printf("%d\t%d\n", nx, ny);
  38.  
  39.    for (i=0; i<nx*ny; i++) {
  40.       (void)fgets(line, MAXLINE, f_in);
  41.       zd = atoFFP(line);
  42.       if (debug) printf("%f\t", zd);
  43.       (void)fwrite((char *)&zd,4,1,f_out);
  44.    }
  45.    printf("%d floats written to t2f.out\n", i);
  46.  
  47.    fclose(f_in);
  48.    fclose(f_out);
  49.    return(0);
  50. }
  51.